//1.借助构造函数
function SuperType(){
    this.colors=["red","blue","green"]
}

function SubType(){
    SuperType.call(this);
}

var instancel = new SuperType();
instancel.colors.push("black");
console.log(instancel.colors);

var instance2 = new SuperType();
console.log(instance2.colors);

//组合继承
//缺点：调用了两次超类的构造函数，导致基类的原型对象中增添了不必要的超类的实例对象中的所有属性。
function SuperType(name){
    this.name = name
    this.colors = ["red","blue","green"]
}
SuperType.prototype.sayName = function(){
    console.log(this.name);
}
function SubType(name,age){
    SuperType.call(this,name);
    this.age=age;
}
//继承方法
SubType.prototype = new SuperType(); 
SubType.prototype.constructor = SubType;
SubType.prototype.sayAge = function(){
    console.log(this.age);
}

var instancel1 = new SubType("james",9);
instancel.colors.push("black");
console.log(instancel.color);
instancel1.sayName();
instancel1.sayAge();

//原型式继承:是可以基于已有的对象创建新的对象，同时还不必因此创建自定义类型
function object(o){
    function F(){}
    F.prototype = o;
    return new F();
}

//寄生式继承：创建一个仅用于封装继承过程的函数，该函数在内部以某种方式增强对象，最后放回这个对象
function createAnother(original){
    var clone = object(original);
    clone.sayHi = function(){
        console.log("hi");
    }
    return clone;
}
var person = {
    name:"james"
}
var anotherPerson = createAnother(person);
anotherPerson.sayHi()

//寄生式组合继承
function inheritPrototype(SubType,SuperType){
    var prototype = object(superType.prototype);
    prototype.constructor = SubType;
    SubType.prototype = prototype;
}


